
<template>
  <div>
    <div class="container">
      <div class="handle-box">
         <!-- <el-button type="primary" size="small">复训预警</el-button>
         <el-button type="primary" size="small">考试不合格记录</el-button> -->


                <span style="padding:8px;color#242424;">医院名称</span>
                <el-input v-model="query.hosname" placeholder="请输入" style="width:10%"></el-input>
                <!-- <span style="padding:8px;color#242424;" v-if="role==1 || role==4">企业名称：</span>
                <el-input v-model="query.compname" placeholder="请输入企业名称" style="width:10%" @keydown="handleSearch" v-if="role==1 || role==4"></el-input> -->
                <!-- <span style="padding:8px;color#242424;">类型选择：</span>
                <el-radio-group v-model="query.type_px">
                    <el-radio :label="0">全部</el-radio>
                    <el-radio :label="1">初训</el-radio>
                    <el-radio :label="2">复训</el-radio>
                </el-radio-group> -->
                <span style="padding:8px;color#242424;">开始日期:</span>
                <el-date-picker type="date" v-model="query.timepx_st" value-format="yyyy-MM-dd" placeholder="开始日期"></el-date-picker>
                <span style="padding:8px;color#242424;">结束日期:</span>
                <el-date-picker type="date" v-model="query.timepx_ed" value-format="yyyy-MM-dd" placeholder="日期"></el-date-picker>
 

        <!-- <span style="padding: 8px 8px 8px 0">医院名称：</span>
        <el-input
          v-model.trim="query.hosname"
          placeholder=""
          class="handle-input mr10"
       
        ></el-input>
        <span style="padding: 8px"></span> -->

        <el-button
          type="success"
          size="medium"
          icon="el-icon-search"
          @click="handleSearch()"
          >搜索</el-button
        >
        
      </div>
        <!-- <div class="handle-box" v-if="this.activeIndex != 999"> -->
             <!-- <span style="padding:8px;color#242424;">班级:</span>
                <el-input v-model="modelList.classname.value" placeholder="请输入班级" style="width: 10%"></el-input>
                -->
      
                <!-- <span style="padding:8px;color#242424;">发证日期:</span>
                <el-date-picker type="date" v-model="time_cartprint" value-format="yyyy-MM-dd" placeholder="发证日期"></el-date-picker> -->
   <!-- <span style="padding:8px;color#242424;">所选项目:</span>
                <el-input v-model="modelList.classname.value" placeholder="所选项目" style="width:10%" ></el-input> -->

                <!-- <span style="padding:8px;color#242424;margin-left:10px;">状态：</span>
                <el-select v-model="query.is_del" placeholder="请选择">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select> -->
                <!-- <span style="padding: 8px"></span>
                <el-button type="primary" size="small" @click="handleEdit('pb', 1)">保存</el-button> -->
          
        <!-- </div> -->

      <!-- <div class="handle-box" style="display: flex">
        <el-button
          type="primary"
          icon="el-icon-document-add"
          size="medium"
          @click="createMethod"
          >新增</el-button
        >
         
      </div> -->
             <div class="handle-box">
                <div class="base-button-top">
                  <div>
                        <span>检查数：{{pageTotal}}</span>
                        <el-divider direction="vertical"></el-divider>
                        <span>影像数：{{hzinfo.yxnum}}</span> 
                        <el-divider direction="vertical"></el-divider>
                        <span>胶片数：{{hzinfo.jpnum}}</span>
                        <el-divider direction="vertical"></el-divider>
                        <span>报告数：{{hzinfo.reportnum}}</span>
                    </div>                      
                     <!-- <el-button size="small" type="primary" @click="printingMethodAll" style="margin-right:10px;">批量打印</el-button> -->
<!--                  <downExcel :fetch-data="excelExport" :json-fields="jsonFields" :fill-name="fillName" :success="excelSuccess"  v-if=" (role==1 || role==4)" ></downExcel> -->
                   
                 </div>
            </div>
      <el-table
        :data="tableData"
        border
        ref="multipleTable"
        header-cell-class-name="table-header"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column label="序号" width="55">
          <template slot-scope="scope">{{
            scope.$index + (query.pageIndex - 1) * query.pageSize + 1
          }}</template>
        </el-table-column>
        <el-table-column label="患者名称" align="center">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column> 
        <el-table-column label="检查号" align="center">
          <template slot-scope="scope">{{ scope.row.checkno }}</template>
        </el-table-column>
        <el-table-column label="检查医院" align="center">
          <template slot-scope="scope">{{ scope.row.hospital }}</template>
        </el-table-column>
       
        <el-table-column
          label="采集时间"
          align="center"
          :formatter="this.$DATEFORMAT.formatDateTime"
          prop="create_time"
        ></el-table-column>
        <!-- <el-table-column
          label="更新采集时间"
          align="center"
          :formatter="this.$DATEFORMAT.formatDateTime"
          prop="updatenate"
        ></el-table-column> -->
        <el-table-column label="报告数" align="center">
          <template slot-scope="scope">{{ scope.row.reportnum }}</template>
        </el-table-column>
        <el-table-column label="胶片数" align="center">
          <template slot-scope="scope">{{ scope.row.filmnum }}</template>
        </el-table-column>
        <el-table-column label="影像数" align="center">
          <template slot-scope="scope">{{ scope.row.dicomnum}}</template>
        </el-table-column>
        <!-- <el-table-column
          label="创建时间"
          :formatter="this.$DATEFORMAT.formatDate"
          align="center"
          prop="create_time"
        ></el-table-column> -->
        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
               <el-button  type="text" @click="handleEdit(scope.row, 11)">影像</el-button>
             <el-button  type="text" @click="handleEdit(scope.row, 3)" v-if="scope.row.status==3">报告信息</el-button>

             <!--
            <span style="padding: 8px"></span>
            <el-button
              icon="el-icon-camera"
              type="text"
              @click="handleEdit(scope.row, 2)"
              >影像</el-button
            > -->
            <span style="padding: 8px"></span>
            <!-- <el-button
              icon="el-icon-edit"
              type="text"
              @click="handleEdit(scope.row, 3)"
              >写报告</el-button
            >
            <span style="padding: 8px"></span> -->
            <!-- <el-popconfirm
              title="确定删除吗？"
              @confirm="handleDelete(scope.row.id, scope.row.title)"
            >
              <el-button
                type="text"
                slot="reference"
                icon="el-icon-delete"
                style="color: #f56c6c"
                >删除</el-button
              >
            </el-popconfirm> -->
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          layout="sizes,total, prev, pager, next, jumper"
          :current-page="query.pageIndex"
          :page-size="query.pageSize"
          :page-sizes="[10, 20, 50, 100, 150, 200]"
          @size-change="handleSizeChange"
          :total="pageTotal"
          @current-change="handlePageChange"
        ></el-pagination>
      </div>
    </div>
    <el-dialog :title="dialogTitle" :visible.sync="dialog" width="50%">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="标题" prop="title">
          <el-input
            v-model.trim="ruleForm.title"
            placeholder="标题名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="详情">
          <el-input
            type="textarea"
            v-model.trim="ruleForm.mark"
            placeholder="详情"
            :rows="5"
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-switch
            v-model="ruleForm.status"
            active-text="禁用"
            inactive-text="启用"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="排序">
          <el-input v-model.trim="ruleForm.sort" placeholder="排序"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
        <el-button type="primary" @click="submitMethod">确定</el-button>
      </span>
    </el-dialog>
    <Effect
      :title="effectTtile"
      :id="effectId"
      :show.sync="effectShow"
    ></Effect>

     <!-- <report-write :title="effectTtile" :id="effectId" :show.sync="effectShow" :report-write-event="reportWriteEvent()"></report-write>  -->
    <el-dialog title="报告" :visible.sync="dialogBg" width="80%" top="2%">
      <iframe v-if="dialogBg" :src="pdfUrl" frameborder="0" style="width:100%;height:80vh"></iframe>
    </el-dialog>

    
  </div>
</template>

<script>
// import reportWrite from "./reportWrite";
import Effect from "./effect";
export default {
  components: { Effect },
  name: "gather",
  data() {
    return {
      treeData: [],
      fileList: [],
      dialog: false,
      dialogShow: false,
      effectShow: false,
      effectId: "",
      effectTtile: "", 
       ialog: false,
      dialogBg: false,
      disabled: false,
      dialogsharetitle: '',
      dialogshare: false,
      dialogcopytitle: '',
      dialogcopy: false,
      query: {
         uname: '',
                pid: 0,
                pxjgid: '',
                compname: '',
                pageIndex: 1,
                pageSize: 20,
                hosname: '',
                is_del: '',
                listType: 2,
                timepx_st:'',
                timepx_ed:'',
      },
      tableData: [],
      pageTotal: 0,
      multipleSelection: [],
      ruleForm: {
        title: "",
        mark: "",
        sort: "",
        status: false,
      },
      rules: {
        title: [{ required: true, message: "请输入名称", trigger: "blur" }],
      },
      dialogTitle: "新增",
      id: null,
      pdfUrl:'',
      hzinfo:[],
    };
  },
  created() {
    this.initAjaxMethod();
  },
  methods: {
    handleSource(data) {
      this.$router.push({
        path: "/resourceEdit",
        query: { id: data.id, type: 2 },
      });
    },
    //重置
    resultClick() {
      this.query = {
        pageIndex: 1,
        pageSize: 10,
        keyword: "",
      };
      this.initAjaxMethod();
    },
    successMethod() {
      this.dialog = false;
      this.$set(this.query, "pageIndex", 1);
      this.initAjaxMethod();
    },
    // 触发搜索按钮
    handleSearch11() {
      this.$set(this.query, "pageIndex", 1);
      this.initAjaxMethod();
    },
     // 触发搜索按钮
        handleSearch() {
            // console.log(this.query);return
            this.$set(this.query, 'pageIndex', 1);

            this.initAjaxMethod();
        },
    // 分页导航
    handlePageChange(val) {
      this.$set(this.query, "pageIndex", val);
      this.initAjaxMethod();
    },
    handleSizeChange(e) {
      this.query.pageSize = e;
      this.initAjaxMethod();
    },
    // 删除操作
    handleDelete(id, detail) {
      this.delAjaxMethod(id, detail);
    },
    // 多选操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delAllSelection() {
      if (this.multipleSelection.length <= 0) {
        return this.$message.error("请选择一个目录");
      }
      this.$confirm("确定要删除吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          let ids = this.multipleSelection.map((item) => item.id);
          this.delAjaxMethod(ids.join(","));
        })
        .catch(() => {});
    },
    createMethod() {
      this.ruleForm = {
        title: "",
        mark: "",
        sort: "",
        status: false,
      };
      this.dialog = true;
      this.id = null;
      this.dialogTitle = "新增";
      setTimeout(() => {
        this.$refs["ruleForm"].clearValidate();
      }, 200);
    },
    // 编辑操作
    handleEdit001(data, flag) {
      if (flag == 1) {

      } else if (flag == 2) {
        this.effectId = data.id;
        this.effectTtile = data.name;
        this.effectShow = true;
      } else if (flag == 3) {
        this.dialogShow=true;
        // this.$router.push({path:'/reportWrite'})
      }
    },

      // 编辑操作
    async handleEdit(data, flag) {
      if (flag == 1) {
        this.stepsActive = 1;
        console.log("xx",data);
        this.ruleForm = {
          bodynum: data.bodynum,
          checkno: data.checkno,
          name: data.name,
          sex: data.sex,
          mobile: data.mobile,
          ishospitalization: data.ishospitalization,
          hospitalizationNo: data.hospitalizationNo,
          bedNo: data.bedNo,
          outpatientServiceNo: data.outpatientServiceNo,
          inspectionarea: data.inspectionarea,
          weight: data.weight,
          idCard: data.idCard,
          age: data.age,
          urgencyDegree: data.urgencyDegree,
          checkTypeName: data.checkTypeName,
          healthCheck: data.healthCheck,
          applyDepartmentName: data.applyDepartmentName,
          sendDoctor: data.sendDoctor,
          clinicalDiagnosis: data.clinicalDiagnosis,
          ageType:data.ageType || '岁'
        }
        this.dialog = true;
        this.id = data.id;
        this.dialogTitle = "编辑";
        this.$nextTick(() => {
          if (this.$refs["ruleForm"]) {
            this.$refs["ruleForm"].clearValidate();
          }
        });
      } else if (flag == 2) {
        var url = this.$API.DOMAIN_NAME+'/public/toDicom1.html?type=yzd&token=adfsfeef&zid=' + data.id+'&checknom='+data.checkno_m;
        window.open(url, '_blank', 'menubar=no,toolbar=no, status=no,scrollbars=yes');
      } else if (flag == 3) {
        console.log("222",data.id);
        let url=this.$API.DOMAIN_NAME+this.$API.CLOUDDIAGNOSIS_VIEWREPORT+'?id='+data.id+'&.pdf';
        this.pdfUrl= `${this.$API.DOMAIN_NAME}/web/pdf/web/viewer.html?file=${encodeURIComponent(url)}`;
        this.dialogBg=true;
      } else if (flag == 4) {
        // this.$router.push({path:'/reportWrite',query:{id:data.id}})
        this.effectTtile=data.name;
        this.effectId=data.id;
        this.effectDerail=data;
        this.effectShow=true;
      }else if (flag == 'share') {

 
        this.detailMethod(data.id);
        console.log("xx",data);

        // this.ruleFormshare = {
        //   shareurl: data.shareurl,
        //   ewmurl:data.shareewmurl,
           
        // }
        // this.shareObj = {
        //   shareurl: data.shareurl,
        //   ewmurl:data.shareewmurl,
           
        // }    
        // this.dialogshare = true;
        // this.id = data.id;
        // this.dialogsharetitle = "分享";
   
      } else if (flag == 10) {
        // pacsviewendtime  cseriesid_pacs
      
     
      } else if (flag == 11) {
        // 联氪测试         
       if(data.studyuid=="" || data.studyuid=="null" ){
               this.$message.error("缺少SUID");return false;
        } 
 
                        var targetApp="viewer";
                        var vc = "link"; //vendor code
                        // var hostAddr = "view.blue-imaging.com"; // 蓝影
                        var hostAddr =this.$API.DCM_viewurl;
                        //  var hostAddr = "pacs.link-imaging.com";//window.location.host;
                         //Url过期时间（单位为秒）
                        var expires = data.expires;                 
                        var signature =data.signature;          
                        var serverAddr =data.serverAddr;
                        var linkviewurl = "https://" + hostAddr + "/Viewer/Index"
                        linkviewurl = linkviewurl + "?ds=rest" + "&serverAddr=" + serverAddr + "&vc=" + vc +
                        "&expires=" + expires + "&signature=" + signature + "&targetApp=" + targetApp;
                         window.open(linkviewurl, "Viewer");//打开连接


     
      } else if (flag == "copy") {
            //  inspectionAreanew:
          this.copyObj = {
              inspectionarea: data.inspectionarea,
                mobile: data.mobile,   
                // ewmurl:data.shareewmurl,
                
              }   
          this.dialogcopy = true;
          this.id = data.id;
          this.dialogcopytitle = "复制"; 
        

      }

      
    },


    //列表加载
    initAjaxMethod() {
      this.$http
        .post(this.$API.GATHER_INDEX, {
          pageIndex: this.query.pageIndex,
          pageSize: this.query.pageSize,
          hosname: this.query.hosname,
           uname: this.query.uname, 
                    todo: 'getpaibanstatus0',
                    // listType:this.query.listType,
                    timepx_st:this.query.timepx_st,
                    timepx_ed:this.query.timepx_ed,
                    comfrom:"lysel"
        })
        .then((res) => {
          console.log("媒资列表", res);
          if (res.code == 1) {
            this.tableData = Array.isArray(res.data.list) ? res.data.list : [];
            this.pageTotal = res.data.total;
            this.hzinfo=res.data.hzinfoarr;
          }
        });
    },
    submitMethod() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.ruleForm.status = this.ruleForm.status == false ? 1 : 0;
          const loading = this.$loading({ text: "加载中..." });
          const url = this.id ? this.$API.GATHER_EDIT : this.$API.GATHER_ADD;
          if (this.id) this.ruleForm.id = this.id;
          this.$http
            .post(url, this.ruleForm)
            .then((res) => {
              // console.log("公海列表", res);
              if (res.code == 1) {
                this.$message.success("操作成功");
                if (!this.id) this.query.pageIndex = 1;
                this.dialog = false;
                this.initAjaxMethod();
              } else {
                this.$message.error(res.msg);
              }
              loading.close();
            })
            .catch((err) => {
              loading.close();
              this.$message.error(err.msg);
            });
        } else {
          this.$message.error("有必填项目未填写");
        }
      });
    },
    //删除单个
    delAjaxMethod(id) {
      const loading = this.$loading({ text: "加载中..." });
      this.$http
        .post(this.$API.GATHER_DEL, { ids: id })
        .then((res) => {
          loading.close();
          if (res.code == 1) {
            this.$message.success("删除成功");
            this.initAjaxMethod();
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    }
  },
};
</script>

<style scoped>
.container {
  padding: 20px;
}
.handle-select {
  width: 120px;
}

.handle-input {
  width: auto;
  display: inline-block;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #f56c6c;
}
.mr10 {
  margin-right: 10px;
}
.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
.demo-drawer__content {
  margin: 0 auto;
  width: 80%;
  border: 1px solid #fafafa;
}
.sort-title {
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.sort-group {
  display: flex;
  align-items: center;
  margin-left: 30px;
  font-size: 14px;
}
.sort-group:hover {
  cursor: pointer;
}
.sort-group:hover span {
  color: #409eff;
}
.sort-group i {
  font-weight: bold;
}
.sort-active {
  color: #409eff;
}

</style>
